package cn.csg.iotplatform.module.system.controller.admin.userdept;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.csg.iotplatform.framework.common.pojo.PageParam;
import cn.csg.iotplatform.framework.common.pojo.PageResult;
import cn.csg.iotplatform.framework.common.pojo.CommonResult;
import cn.csg.iotplatform.framework.common.util.object.BeanUtils;
import static cn.csg.iotplatform.framework.common.pojo.CommonResult.success;

import cn.csg.iotplatform.framework.excel.core.util.ExcelUtils;

import cn.csg.iotplatform.framework.operatelog.core.annotations.OperateLog;
import static cn.csg.iotplatform.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.csg.iotplatform.module.system.controller.admin.userdept.vo.*;
import cn.csg.iotplatform.module.system.dal.dataobject.userdept.UserDeptDO;
import cn.csg.iotplatform.module.system.service.userdept.UserDeptService;

@Tag(name = "管理后台 - 用户设备单位授权")
@RestController
@RequestMapping("/system/user-dept")
@Validated
public class UserDeptController {

    @Resource
    private UserDeptService userDeptService;

    @PostMapping("/save")
    @Operation(summary = "保存用户设备单位授权")
    @PreAuthorize("@ss.hasPermission('system:user-dept:create')")
    public CommonResult<Boolean> createUserDept(@Valid @RequestBody UserDeptSaveReqVO createReqVO) {
        userDeptService.createUserDept(createReqVO);
        return success(true);
    }

    @GetMapping("/getAuthDeptIds")
    @Operation(summary = "获取用户设备单位授权")
    @PreAuthorize("@ss.hasPermission('system:user-dept:query')")
    public CommonResult<UserDeptAuthRespVO> getAuthDeptIds(@RequestParam("userId") Long userId) {
        return success(userDeptService.getAuthDeptIds(userId));
    }

}